import { Controller, Get, Post, Body, Patch, Param } from '@nestjs/common';
import { OrganizationService } from './organization.service';
import { CreateOrganizationDto } from './dto/create-organization.dto';
import { UpdateOrganizationDto } from './dto/update-organization.dto';
import { Result } from '../common/dto/common.result';

@Controller('organization')
export class OrganizationController {
  constructor(private readonly organizationService: OrganizationService) {
  }

  @Post('save')
  async create(@Body() createOrganizationDto: CreateOrganizationDto) {
    await this.organizationService.create(createOrganizationDto);
    return Result.success();
  }

  @Get('/info/:id')
  async findOne(@Param('id') id: number) {
    return Result.successData(await this.organizationService.findOne(id));
  }

  @Patch('/info')
  async update(@Body() updateOrganizationDto: UpdateOrganizationDto) {
    await this.organizationService.update(
      updateOrganizationDto.id,
      updateOrganizationDto,
    );
    return Result.success();
  }
}
